<template>
  <el-form :model="user" :rules="checkUser" ref="user" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <h1 class="title" style='display : inline-block'>
      <span>Phal<i style="color:#20a0ff">Admin</i></span>
    </h1>
    <!-- @TODO 文字居中问题 -->
    <h2 class="title-text" style='display:inline-block'> 系统登录</h2>
    <el-form-item prop="account">
      <el-input type="text" v-model="user.account" icon="user" auto-complete="off" @keyup.enter.native="userlogin" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input type="password" v-model="user.password" icon="pass" auto-complete="off" @keyup.enter.native="userlogin" placeholder="密码"></el-input>
    </el-form-item>
    <el-checkbox v-model="checked" class="remember" style="margin:0px 0px 20px 0px;">记住密码</el-checkbox>
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="userlogin" :loading="logining">登录</el-button>
      <a class="login-a" style="margin:0px 66% 20px 0px;" href="#/account/regist">用户注册</a>
      <a class="login-a" href="#/account/regist">忘记密码</a>
    </el-form-item>
  </el-form>
</template>
<script>
// 加载Session
import { Session,Type} from "lib"
import LoginRules from './LoginRules'
import {
  mapGetters
} from 'vuex'
import {
  mapActions
} from 'vuex'

export default {
  computed: {
    ...mapGetters({
      logining: Type.LOGIN_GET_LOGINING
    })
  },
  data() {
    return {
      user: {
        account: "",
        password: ""
      },
      checkUser: LoginRules,
      checked: false
    };
  },
  created: function() {
    var account = Session.get("account");
    var password = Session.get("password");
    var checked = Session.get("checked");
    this.user.account = account ? account : "";
    this.user.password = checked ? password : "";
    this.checked = checked ? checked : false;
  },
  methods: {
    // 登陆按钮点击事件
    userlogin() {
      this.$store.dispatch(Type.LOGIN,this)
    }
  }
}
</script>
<style lang="scss" scoped>
@import "Login.css";
</style>
